-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
?? Operator results in "Unexpected Token" err when used in package #9468
?? Operator results in "Unexpected Token" err when used in package #9468
Comments
I'm encountering this issue too – here's a repo to reproduce: https://github.com/bitjson/bitauth-cra (
The nullish coalescing operator works as expected in Does anyone have any tips for how to debug this issue? |
As another data point, the bitauth-ide repo is running |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
For any TypeScript library authors having trouble with this, one workaround is to switch your compilation target from |
Same error with |
Changing browser targets from "browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}, to "browserslist": [
">0.2%",
"not dead",
"not op_mini all"
], solved my issue. |
EDIT: Does having last 1 version for production makes this fail to build? I need to only support modern browsers - and transpilation increases bundle size. Looks like 4.0.0 was released - but hasn't been properly tested. Anyone can confirm that 4.0.0 still doesn't work with ?? (with or without TS)? |
Still getting the error on 4.0.0
|
I tried the browserslist workaround from @bkiac and it worked for me (I could build debug but not production, now I can do both.) I'm on node 12.18.4 and the build is working fine for me. Oddly enough, my coworker cannot build the project for debug or production. We don't have react-scripts installed so it might be an issue unrelated to react-scripts |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
I'm gonna bump it. But the fix may be to use CRACO or something to configure 4.0.1. |
any update here? |
It happens to me on 4.0.1 , and I don't know any other workaround than forcing other libraries to not use esnext as the compilation target ( #9468 (comment) ). Which is far from nice. |
Is there any way to fix this with a javascript module? (The module I'm using gives the same error, but it was written in javascript). Do I have to edit the module myself? |
./node_modules/@react-leaflet/core/esm/path.js 10:41
| element.instance.setStyle(options); ------- herte is my error guys. please help me.. |
@acrabb
Deleting the node_modules/.cache works for me. |
Update browserlist to avoid nullish coalescing error with most recent version of @tanstack/react-query (see https://github.com/facebook/create-react-app/issues/9468\#issuecomment-694191642)
Update browserlist to avoid nullish coalescing error with most recent version of @tanstack/react-query (see https://github.com/facebook/create-react-app/issues/9468\#issuecomment-694191642)
Update browserlist to avoid nullish coalescing error with most recent version of @tanstack/react-query (see https://github.com/facebook/create-react-app/issues/9468\#issuecomment-694191642)
Update browserlist to avoid nullish coalescing error with most recent version of @tanstack/react-query (see https://github.com/facebook/create-react-app/issues/9468\#issuecomment-694191642)
Update browserlist to avoid nullish coalescing error with most recent version of @tanstack/react-query (see facebook/create-react-app#9468)
Update browserlist to avoid nullish coalescing error with most recent version of @tanstack/react-query (see facebook/create-react-app#9468)
Update browserlist to avoid nullish coalescing error with most recent version of @tanstack/react-query (see facebook/create-react-app#9468)
Update browserlist to avoid nullish coalescing error with most recent version of @tanstack/react-query (see facebook/create-react-app#9468)
was causing some compilation issues due to react scripts 4 and esm modules. see facebook/create-react-app#9468 (comment)
Deleting the node_modules/.cache worked for me. Thanks @tkforce |
this worked for me. thanks much. |
{
"name": "wits",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --open --config webpack.dev.js",
"build": "webpack --config webpack.prod.js",
"analyz": "webpack --config webpack.analyzer.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/plugin-transform-runtime": "^7.12.15",
"@babel/polyfill": "^7.11.5",
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@babel/runtime": "^7.12.13",
"babel-loader": "^8.1.0",
"clean-webpack-plugin": "^3.0.0",
"css-loader": "^3.6.0",
"file-loader": "^6.0.0",
"html-loader": "^1.1.0",
"html-webpack-plugin": "^4.3.0",
"mini-css-extract-plugin": "^0.9.0",
"node-sass": "^4.14.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"sass-loader": "^8.0.2",
"style-loader": "^1.2.1",
"webpack": "^4.43.0",
"webpack-bundle-analyzer": "^3.8.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0",
"webpack-merge": "^4.2.2"
},
"dependencies": {
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.56",
"@sweetalert/with-react": "^0.1.1",
"axios": "^0.20.0",
"canvas-gauges": "^2.1.7",
"classnames": "^2.2.6",
"downsample-lttb": "0.0.1",
"expression-eval": "^5.0.0",
"i18next": "^19.4.5",
"i18next-browser-languagedetector": "^4.2.0",
"leaflet": "^1.9.3",
"moment": "^2.29.4",
"plotly.js": "^2.18.2",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-alert": "^7.0.1",
"react-alert-template-basic": "^1.0.0",
"react-container-dimensions": "^1.4.1",
"react-dom": "^16.13.1",
"react-draggable": "^4.4.5",
"react-grid-layout": "^1.3.4",
"react-helmet-async": "^1.3.0",
"react-i18next": "^11.5.0",
"react-leaflet": "^4.2.1",
"react-plotly.js": "^2.5.1",
"react-query": "^3.39.1",
"react-responsive-carousel": "^3.2.23",
"react-router-dom": "^5.2.0",
"use-interval": "^1.4.0",
"use-window-focus": "^1.4.2"
},
"browserslist": [
">0.2%",
"not dead",
"not op_mini all"
]
} and i am encountering the same error how can i resolve this? |
My solution to the [?? Operator results in "Unexpected Token"] ERROR was to install @babel/plugin-proposal-logical-assignment-operators and @babel/plugin-proposal-nullish-coalescing-operator
|
Thanks this answer worked! https://stackoverflow.com/a/67747605 Like @ferm12, you said @babel/plugin-proposal-nullish-coalescing-operator this solved the issue for me |
@shahsawar92 I am glad you were able to solve your problem. |
@ferm12 i am having an old repo which is at react 16 version. the above issue is still persisting even though I updated the configs in babel
babel.config.js
what is the issue here? is it with react versions? Could you give solution to this? |
I just had this issue while using node 12 in an old environment, |
@jamime Just curious if the whole node_modules are also parsed by a babel plugin would'nt it make it slower to start react app in dev mode or make hot reloading slower ? |
This code is the fast fix the issue.I use craco,add the babel plugin is well fix this. Thx @dhiren-eng |
Describe the bug
If you import a package that uses ?? operator in code, create react app will fail when debugging.
This issue seems to appear only when debugging with such a library. (npm run start)
It builds (npm run build) without errors. So the toolchain for start vs build is in question here.
The operator works fine if used directly - not in the imported library code.
Did you try recovering your dependencies?
Issues occurred with multiple CRAs even with reinstalling node modules.
Which terms did you search for in User Guide?
Null Coalescing Operator Create React App
There seems to be an issue about optional chaining.
Environment
Windows 10 10.0.17763
npm 6.14.5
node 14.4.0
Google Chrome was used to ensure async, let, const, classes, and ?? support.
Steps to reproduce
Expected behavior
The application should compile and run successfully when started or when built..
Actual behavior
The application fails to compile due to the ?? in the library.
Failed to Compile,
Unexpected token
You may need an additional loader to handle the result of these loaders.
Reproducible demo
If needed I can brew something up. This was found in a work project.
The text was updated successfully, but these errors were encountered: